package com.firefly.admin.config.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.firefly.admin.common.annotations.annotation.OperationLog;
import com.firefly.admin.common.enums.OperationModuleEnum;
import com.firefly.admin.common.enums.OperationTypeEnum;
import com.firefly.admin.common.vo.Result;
import com.firefly.admin.monitor.vo.SelectResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.firefly.admin.config.entity.FySystemSensitiveConfig;
import com.firefly.admin.config.service.FySystemSensitiveConfigService;
import com.firefly.admin.config.vo.SystemSensitiveConfigQueryVo;
import com.firefly.admin.config.vo.SystemSensitiveConfigStatusUpdateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "系统敏感数据配置接口API")
@RestController
@RequestMapping("/system/sensitive/config")
public class FySystemSensitiveConfigController {
    @Autowired
    private FySystemSensitiveConfigService fySystemSensitiveConfigService;

    /**
     * 分页查询系统敏感数据配置接口
     *
     * @param systemSensitiveConfigQueryVo 系统敏感配置查询条件
     * @return 敏感配置列表
     */
    @ApiOperation(value = "分页查询系统敏感数据配置接口", notes = "分页查询系统敏感数据配置接口", httpMethod = "GET")
    @PreAuthorize(value = "hasAuthority('system:sensitive:config')")
    @GetMapping("/list")
    public Result<Page<FySystemSensitiveConfig>> getSystemSensitiveConfigList(SystemSensitiveConfigQueryVo systemSensitiveConfigQueryVo) {
        return fySystemSensitiveConfigService.getSystemSensitiveConfigList(systemSensitiveConfigQueryVo);
    }

    /**
     * 系统敏感数据配置新增接口
     *
     * @param fySystemSensitiveConfig 系统敏感数据配置
     * @return 新增结果
     */
    @ApiOperation(value = "系统敏感数据配置新增接口", notes = "系统敏感数据配置新增接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_SENSITIVE_CONFIG, operateDesc = "敏感数据配置新增")
    @PreAuthorize(value = "hasAuthority('system:sensitive:config:add')")
    @PostMapping("/add")
    public Result<FySystemSensitiveConfig> add(@RequestBody FySystemSensitiveConfig fySystemSensitiveConfig) {
        return fySystemSensitiveConfigService.add(fySystemSensitiveConfig);
    }

    /**
     * 系统敏感数据配置编辑接口
     *
     * @param fySystemSensitiveConfig 系统敏感数据配置
     * @return 编辑结果
     */
    @ApiOperation(value = "系统敏感数据配置编辑接口", notes = "系统敏感数据配置编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_SENSITIVE_CONFIG, operateDesc = "敏感数据配置编辑")
    @PreAuthorize(value = "hasAuthority('system:sensitive:config:update')")
    @PostMapping("/update")
    public Result<FySystemSensitiveConfig> update(@RequestBody FySystemSensitiveConfig fySystemSensitiveConfig) {
        return fySystemSensitiveConfigService.update(fySystemSensitiveConfig);
    }

    /**
     * 系统敏感数据配置状态修改接口
     *
     * @param systemSensitiveConfigStatusUpdateVo 系统敏感数据配置状态编辑参数
     * @return 操作结果
     */
    @ApiOperation(value = "系统敏感数据配置状态修改接口", notes = "系统敏感数据配置状态修改接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_SENSITIVE_CONFIG, operateDesc = "敏感数据配置状态修改")
    @PreAuthorize(value = "hasAuthority('system:sensitive:config:update:status')")
    @PostMapping("/update/status")
    public Result<FySystemSensitiveConfig> updateStatus(@RequestBody SystemSensitiveConfigStatusUpdateVo systemSensitiveConfigStatusUpdateVo) {
        return fySystemSensitiveConfigService.updateStatus(systemSensitiveConfigStatusUpdateVo);
    }

    /**
     * 系统敏感数据配置删除接口
     *
     * @param configId 配置ID
     * @return 删除结果
     */
    @ApiOperation(value = "系统敏感数据配置删除接口", notes = "系统敏感数据配置删除接口", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "configId", required = true, value = "配置ID", paramType = "query", dataType = "Long")
    })
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_SENSITIVE_CONFIG, operateDesc = "敏感数据配置删除")
    @PreAuthorize(value = "hasAuthority('system:sensitive:config:delete')")
    @PostMapping("/delete")
    public Result<String> delete(Long configId) {
        return fySystemSensitiveConfigService.delete(configId);
    }

    /**
     * 敏感类型枚举列表查询接口
     *
     * @return 敏感类型列表
     */
    @ApiOperation(value = "敏感类型枚举列表查询接口", notes = "敏感类型枚举列表查询接口", httpMethod = "GET")
    @GetMapping("/select/enum/list")
    public Result<Map<String, List<SelectResult>>> getSensitiveTypeEnumList() {
        return fySystemSensitiveConfigService.getSensitiveTypeEnumList();
    }

}
